package com.dzxcqmxm.servlet.user;

import com.dzxcqmxm.Dao.UserDao;
import com.dzxcqmxm.Dao.impl.UserDaoImpl;
import com.dzxcqmxm.HelloServlet;
import com.dzxcqmxm.JB.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Payboi
 * @create 2022/6/2-22:00
 * @FileName findUserByNameServlet
 * @Description
 */
@WebServlet("/findUserByNameServlet")
public class findUserByNameServlet extends HelloServlet{
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserDao userDao = new UserDaoImpl();
        User user = new User();
        //获取页面跳转的时候携带的参数
        user.setUserName(new String(request.getParameter("UserName" ).getBytes("iso-8859-1"),"UTF-8"));

        try {
            user = userDao.findUserByUserName(user.getUserName());
        } catch (Exception e) {
            e.printStackTrace();
        }

        //session会话对象可以数据共享于一次会话
        request.getSession().setAttribute("user", user);
        response.sendRedirect("/dzxc/admin/user/findUserByName.jsp");

    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            doPost(request, response);
        } catch (ServletException e) {
            e.printStackTrace();
        }
    }
}
